package com.net.framework.help.httprequest;

import com.net.framework.help.utils.StringUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;

/**
 * 参数拼接公共类
 *
 * @author zhangxiaobin
 */
public class RequestParamBean extends JSONObject {
//    private privateJSONObject input;

    public RequestParamBean() {
        setToken();
        try {
            put("version_type", 1);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

//    public JSONObject getInput() {
//        return input;
//    }

    //    public void setInput(JSONObject input) {
//        this.input = input;
//    }
    public void setPage(int page) {
        try {
            put("page", page + "");
            put("size", 10 + "");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public void setToken() {
        if(!StringUtil.isBlank(OkHttp3Utils.userToken)){
            try {
                put("token", OkHttp3Utils.userToken);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 倒叙
     */
    public void setFlashback() {
        try {
            put("order", "id");
            put("orderby", "desc");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }


    public void setInput(String key, String value) {
        try {
            put(key, value);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public void setInput(String key, int value) {
        try {
            put(key, value + "");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public void setInput(String key, long value) {
        try {
            put(key, value + "");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public void setInput(String key, float value) {
        try {
            put(key, value + "");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public void setInput(String key, File file) {
        try {
            put(key, file);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public void setInput(String key, JSONArray jsonArray) {
        try {
            put(key, jsonArray);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public void setInput(String key, Object object) {
        try {
            put(key, object);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
